<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .router-link-active{
      color:red;
    }
  </style>
</head>
<body>
  <div id="app">
    <router-link to="/home" tag="button">首页</router-link>
    <router-link to="/news/2/a/5" tag="button">新闻</router-link>
    <router-link to="/about" tag="button">关于我们</router-link>
    <router-view/>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>
    // 创建 路由组件option
    const Home = {
      template: `
        <div>
          <h2>首页</h2>  
        </div>
      `
    }
    const News = {
      template: `
        <div>
          <h2>新闻</h2>  
        </div>
      `,
      mounted(){
        console.log(this.$route);
      }
    }
    const About = {
      template: `
        <div>
          <h2>关于我们</h2>  
        </div>
      `
    }
    const NotFound =  {
      template: `
        <div>
          <h2>404了</h2>  
        </div>
      `
    }
    const routes = [
      {
        path: '/',
        redirect: '/home'
      },
      {
        path: '/home',
        component: Home
      },
      {
        path: '/news/:id/a/:b',
        component: News
      },
      {
        path: '/about',
        component: About
      },
      {
        path: '*',
        component: NotFound
      }
    ]
    //  创建router 实例
    const router = new VueRouter({
      routes
    })
    const vm = new Vue({
      el: '#app',
      router
    })
  </script>
</body>
</html>